// wtkbinlayout.cpp
//

#include "config.h"
#include "wtk/wtkbinlayout.hpp"
#include "wtk/wtkwidget.hpp"

using namespace wtk;



// BinLayout::add_child
//
void BinLayout::add_child ( Widget &child )
{
  if (child_layout.child)
    {
      WTK_ERROR("multiple children added to Bin layout");
      return;
    }
  child_layout.child = &child;
}



// BinLayout::remove_child
//
void BinLayout::remove_child ( Widget &child )
{
  if (child_layout.child != &child)
    {
      WTK_ERROR("wrong child removed from Bin layout");
      return;
    }
  child_layout.child = nullptr;
}



// BinLayout::clear
//
void BinLayout::clear ()
{
  child_layout.child = nullptr;
}



// BinLayout::size_request
//
void BinLayout::size_request ( SizeRequest &req )
{
  WTK_TRACE("BinLayout.size_request()");

  if (child_layout.child && child_layout.child->is_visible())
    {
      child_layout.child->size_request(req);
    }
  else
    {
      req.width = 0;
      req.height = 0;
    }
  req.width += 8;
  req.height += 8;
}



// BinLayout::size_allocate
//
void BinLayout::size_allocate ( const Allocation &alloc )
{
  WTK_TRACE("BinLayout.size_allocate()");

  if (child_layout.child && child_layout.child->is_visible())
    {
      Allocation child_alloc{4, 4, alloc.width - 8, alloc.height - 8};
      child_layout.child->size_allocate(child_alloc);
    }
}
